<template>
	<view class="add_comm">
		<view class="add_comm_title">小区信息</view>
		<view class="ele_title_left bg-white padding-left-sm padding-bottom-xs">
			<view class="ele_title_inner padding-xs">{{info.residential_quarters_name}}</view>
			<view class="ele_address">
				<image class="ele_address_img" src="../../../common/img/dizhi_hui.png" mode=""></image>
				<text>{{info.residential_quarters_address}}</text>
			</view>
		</view>
		<view class="add_comm_title">设备信息</view>
		<view class="add_box">
			<!-- <view class="add_inner">
				<view class="add_inner_text">设备信息</view>
				<input class="add_inner_input" @input="getsbinfo" type="text" value="" placeholder="请输入设备信息" />
			</view> -->
			<view class="add_inner">
				<view class="add_inner_text">设备编号</view>
				<input class="add_inner_input" @input="getsbnumber" type="text" value="" placeholder="请输入设备编号" />
			</view>
		</view>
		<view class="add_text_btn" @tap="toadd">保存</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				info:'',
				sbnumber:'',
			}
		},
		onLoad(options) {
			let info=JSON.parse(options.item);
			this.info=info;
		},
		methods: {
			getsbnumber(e){
				this.sbnumber = e.detail.value;
			},
			toadd(){
				if(this.sbnumber.trim()=='' || this.sbnumber.trim()==null){
					uni.showToast({
						icon: 'none',
					    title: '设备编号不能为空'
					});
					return;
				}
				let that=this;
				that.http.tokenreq({
					url: 'devicemanagement/v1/add',
					data:{
						"residential_quarters_guid":that.info.residential_quarters_guid,
						"equipment_number":this.sbnumber,
					}
				}).then((res) => {
					console.log("res="+JSON.stringify(res));
					let e=res.data;
					if(e.code==0 && e.success){
						uni.showModal({
							content: e.message,
							showCancel:false,
							success: function (res) {
								if (res.confirm) {
									uni.redirectTo({
										url:'/pages/equipment/equipmentList/equipmentList?item='+JSON.stringify(that.info)
									})
								}
							}
						});
					}else{
						uni.showToast({
							icon: 'none',
						    title: e.message
						});
					}
				})
			}
		}
	}
</script>

<style>

</style>
